/*
 * Copyright 2002-2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lntea.lnblog.common;

import com.lntea.lnblog.config.Configuration;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 数据库连接工厂类
 * @author lichao
 * @date 2016/6/30 15:57
 */
public class ConnectionFactory {
    //driver class
    private static String driverClass;
    //url
    private static String url;
    //username
    private static String username;
    //password
    private static String password;

    static{
        driverClass = Configuration.getProperty("jdbc.driver");
        url = Configuration.getProperty("jdbc.url");
        username = Configuration.getProperty("jdbc.username");
        password = Configuration.getProperty("jdbc.password");
        try {
            Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public static Connection getConnection(){
        try {
            return DriverManager.getConnection(url,username,password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
